package response

import (
	"Gin-Gorm-boke/boke_common/HttpCode"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ResponseOK(c *gin.Context, data interface{}) {
	response := gin.H{
		"code": HttpCode.SUCCESS,
		"msg":  HttpCode.AppHttpCodeEnumMsg[HttpCode.SUCCESS],
	}
	if data != nil {
		response["data"] = data
	}
	c.JSON(http.StatusOK, response)
}

func RespnseLoginError(c *gin.Context) {
	response := gin.H{
		"code": HttpCode.LOGIN_ERROR,
		"msg":  HttpCode.AppHttpCodeEnumMsg[HttpCode.LOGIN_ERROR],
	}
	c.JSON(http.StatusHTTPVersionNotSupported, response)
}

func ResponseBadRequest(c *gin.Context) {
	response := gin.H{
		"code": 0,
		"msg":  "参数错误",
	}
	c.JSON(http.StatusBadRequest, response)
}

func ResponseUnauthorized(c *gin.Context) {
	response := gin.H{
		"code": 401,
		"msg":  "Unauthorized",
	}
	c.JSON(http.StatusUnauthorized, response)
}

func ResponsePswWrong(c *gin.Context, msg string) {
	response := gin.H{
		"code": 401,
		"msg":  msg,
	}
	c.JSON(http.StatusUnauthorized, response)
}

func ResponseInternalServerError(c *gin.Context) {
	response := gin.H{
		"code": 0,
		"msg":  "服务器错误",
	}
	c.JSON(http.StatusInternalServerError, response)
}
